<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="iOS,Xcode," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="写在前面：多套 build configration 可以方便我们编译成不同的版本，其中可以 不同bundle id 不同 Displa namey，并以此 分化功能上的差异。常见用处：

调试版 可能会需要加入 Reveal SDK, 方便调试视图 调试版可能需要需要使用测试的API接口,而正式版是不能含有此SDK，且使用正式版的API。
Lite，pro 版本 功能上的分化。大部分核心功能相同">
<meta property="og:type" content="article">
<meta property="og:title" content="Xcode-Build-Configration多版本配置">
<meta property="og:url" content="https://tanpengsccd.github.io/2016/10/16/Xcode-Build-Configration多版本配置/index.html">
<meta property="og:site_name" content="tanpengsccd's blog">
<meta property="og:description" content="写在前面：多套 build configration 可以方便我们编译成不同的版本，其中可以 不同bundle id 不同 Displa namey，并以此 分化功能上的差异。常见用处：

调试版 可能会需要加入 Reveal SDK, 方便调试视图 调试版可能需要需要使用测试的API接口,而正式版是不能含有此SDK，且使用正式版的API。
Lite，pro 版本 功能上的分化。大部分核心功能相同">
<meta property="og:image" content="http://oet7vjedr.bkt.clouddn.com/2016121614818742423966.jpg?imageView2/0/format/jpg">
<meta property="og:image" content="http://oet7vjedr.bkt.clouddn.com/20161216148187614526138.jpg?imageView2/0/format/jpg">
<meta property="og:image" content="http://oet7vjedr.bkt.clouddn.com/20161216148187675240155.jpg?imageView2/0/format/jpg">
<meta property="og:image" content="http://oet7vjedr.bkt.clouddn.com/20161216148187879197159.jpg?imageView2/0/format/jpg">
<meta property="og:image" content="http://oet7vjedr.bkt.clouddn.com/20161216148187920028262.jpg?imageView2/0/format/jpg">
<meta property="og:image" content="http://oet7vjedr.bkt.clouddn.com/20161216148188009825013.jpg?imageView2/0/format/jpg">
<meta property="og:updated_time" content="2017-01-07T11:10:35.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Xcode-Build-Configration多版本配置">
<meta name="twitter:description" content="写在前面：多套 build configration 可以方便我们编译成不同的版本，其中可以 不同bundle id 不同 Displa namey，并以此 分化功能上的差异。常见用处：

调试版 可能会需要加入 Reveal SDK, 方便调试视图 调试版可能需要需要使用测试的API接口,而正式版是不能含有此SDK，且使用正式版的API。
Lite，pro 版本 功能上的分化。大部分核心功能相同">
<meta name="twitter:image" content="http://oet7vjedr.bkt.clouddn.com/2016121614818742423966.jpg?imageView2/0/format/jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"right","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 'undefined',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://tanpengsccd.github.io/2016/10/16/Xcode-Build-Configration多版本配置/"/>





  <title> Xcode-Build-Configration多版本配置 | tanpengsccd's blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">tanpengsccd's blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
    
      <h1 class="site-subtitle" itemprop="description"></h1>
    
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="https://tanpengsccd.github.io/2016/10/16/Xcode-Build-Configration多版本配置/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="tanpengsccd">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="http://oet7vjedr.bkt.clouddn.com/2016121815128head.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="tanpengsccd's blog">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="tanpengsccd's blog" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
            
            
              
                Xcode-Build-Configration多版本配置
              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2016-10-16T17:37:17+08:00">
                2016-10-16
              </time>
            

            
              <span class="post-meta-divider">|</span>
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>
              
                <span class="post-meta-item-text">更新于</span>
              
              <time title="更新于" itemprop="dateModified" datetime="2017-01-07T19:10:35+08:00">
                2017-01-07
              </time>
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/iOS/" itemprop="url" rel="index">
                    <span itemprop="name">iOS</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2016/10/16/Xcode-Build-Configration多版本配置/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count" data-disqus-identifier="2016/10/16/Xcode-Build-Configration多版本配置/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          
             <span id="/2016/10/16/Xcode-Build-Configration多版本配置/" class="leancloud_visitors" data-flag-title="Xcode-Build-Configration多版本配置">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>写在前面：<br>多套 build configration 可以方便我们编译成不同的版本，其中可以 不同bundle id 不同 Displa namey，并以此 分化功能上的差异。<br>常见用处：</p>
<ol>
<li>调试版 可能会需要加入 Reveal SDK, 方便调试视图 调试版可能需要需要使用测试的API接口,而正式版是不能含有此SDK，且使用正式版的API。</li>
<li>Lite，pro 版本 功能上的分化。大部分核心功能相同但仍有部分不同</li>
</ol>
<p>此处以我的项目为例。需要新建一个内部测试版（Alpha）和一个企业版（Enterprise），相对于正式版（release），内部测试版需要可以使用测试API地址和新增使用自动更新功能，企业版需要新增使用自动更新功能。<br>|版本|测试版地址|更新提示|<br>|—|:—:|:—:|<br>|Release|X|X|<br>|Debug|O|X|<br>|Enterprise|X|O|</p>
<h1 id="project-配置"><a href="#project-配置" class="headerlink" title="project 配置"></a>project 配置</h1><ol>
<li><p>新增build configration<br><img src="http://oet7vjedr.bkt.clouddn.com/2016121614818742423966.jpg?imageView2/0/format/jpg" alt="2016121614818742423966.jpg"><br>这样便新增一套配置文件 例如我自己命名为“Alpha” 和 “Enterprise”。</p>
</li>
<li><p>新建自定义设置项<br><img src="http://oet7vjedr.bkt.clouddn.com/20161216148187614526138.jpg?imageView2/0/format/jpg" alt="20161216148187614526138.jpg"><br>比如第一个设置项我对应不同版本设置了 不同的 bundle id （这样就可以几个版本的app 同时共存），并把设置项命名为“BUNDLE_IDENTIFIER” 。</p>
</li>
<li><p>设置 bundle ID<br>如下填入 $(BUNDLE_IDENTIFIER) ，即 $(设置项名称)。即可完成 Build Configration 中 bundle id 的差异化<br><img src="http://oet7vjedr.bkt.clouddn.com/20161216148187675240155.jpg?imageView2/0/format/jpg" alt="20161216148187675240155.jpg"><br>其它配置项的差异化 配置方法雷同：如Display name，info plist  path，app icon。</p>
</li>
</ol>
<h1 id="cocoapods-配置"><a href="#cocoapods-配置" class="headerlink" title="cocoapods 配置"></a>cocoapods 配置</h1><p>其实配置很简单，只是一部分童鞋不知道语法<br><code>pod 三方库名称 , :configurations =&gt; [&#39; build名称&#39;]</code></p>
<p><img src="http://oet7vjedr.bkt.clouddn.com/20161216148187879197159.jpg?imageView2/0/format/jpg" alt="20161216148187879197159.jpg"></p>
<h1 id="代码控制"><a href="#代码控制" class="headerlink" title="代码控制"></a>代码控制</h1><ol>
<li>配置cocoapods前需要先配置 project的预处理宏<br><img src="http://oet7vjedr.bkt.clouddn.com/20161216148187920028262.jpg?imageView2/0/format/jpg" alt="20161216148187920028262.jpg"></li>
<li><p>代码<br>宏编译知识看<a href="http://www.cnblogs.com/rusty/archive/2011/03/27/1996806.html" target="_blank" rel="external">这里</a>  </p>
<ol>
<li><p>友盟统计 区别设置渠道</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">#if defined(AlPHA)</div><div class="line">    UMConfigInstance.channelId = @&quot;ALPHA&quot;;</div><div class="line">#elif defined(ENTERPRISE)</div><div class="line"> UMConfigInstance.channelId = @&quot;ENTERPRISE&quot;;</div><div class="line">#endif</div></pre></td></tr></table></figure>
</li>
<li><p>内部测试版 和 企业版 使用 蒲公英SDK 的更新服务</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">#if defined(ALPHA) ||  defined(ENTERPRISE)</div><div class="line"></div><div class="line">    [[PgyManager sharedPgyManager]; startManagerWithAppId:PGY_APP_ID];</div><div class="line">    [[PgyManager sharedPgyManager] setEnableFeedback:NO];</div><div class="line">    [[PgyManager sharedPgyManager] setShakingThreshold:3];</div><div class="line">    [[PgyManager sharedPgyManager] setThemeColor:COLOUR_RED];</div><div class="line">    [[PgyUpdateManager sharedPgyManager]; startManagerWithAppId:PGY_APP_ID];</div><div class="line">    [[PgyUpdateManager sharedPgyManager] checkUpdate];</div><div class="line">   </div><div class="line">#endif</div></pre></td></tr></table></figure>
</li>
</ol>
</li>
</ol>
<h1 id="一些效果"><a href="#一些效果" class="headerlink" title="一些效果"></a>一些效果</h1><p><img src="http://oet7vjedr.bkt.clouddn.com/20161216148188009825013.jpg?imageView2/0/format/jpg" alt="20161216148188009825013.jpg"></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/iOS/" rel="tag"># iOS</a>
          
            <a href="/tags/Xcode/" rel="tag"># Xcode</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/10/09/VPS-CentOS-入手后配置事项-mac客户端/" rel="next" title="VPS(CentOS)入手后配置事项(mac客户端)">
                <i class="fa fa-chevron-left"></i> VPS(CentOS)入手后配置事项(mac客户端)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/10/17/CAC-VPS那些坑/" rel="prev" title="CVC-VPS那些坑">
                CVC-VPS那些坑 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://oet7vjedr.bkt.clouddn.com/2016121815128head.jpg"
               alt="tanpengsccd" />
          <p class="site-author-name" itemprop="name">tanpengsccd</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">7</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">11</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/tanpengsccd" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://git.oschina.net/tanpengsccd" target="_blank" title="Git@OSC">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  Git@OSC
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.jianshu.com/users/ca0f08449f2c" target="_blank" title="简书">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  简书
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://blog.csdn.net/tanpengsccd" target="_blank" title="CSDN">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  CSDN
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#project-配置"><span class="nav-number">1.</span> <span class="nav-text">project 配置</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#cocoapods-配置"><span class="nav-number">2.</span> <span class="nav-text">cocoapods 配置</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#代码控制"><span class="nav-number">3.</span> <span class="nav-text">代码控制</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#一些效果"><span class="nav-number">4.</span> <span class="nav-text">一些效果</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">tanpengsccd</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  

    <script type="text/javascript">
      var disqus_shortname = 'blog-tanpengcd-cn';
      var disqus_identifier = '2016/10/16/Xcode-Build-Configration多版本配置/';

      var disqus_title = "Xcode-Build-Configration多版本配置";


      function run_disqus_script(disqus_script) {
        var dsq = document.createElement('script');
        dsq.type = 'text/javascript';
        dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/' + disqus_script;
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
      }

      run_disqus_script('count.js');

      
        var disqus_config = function () {
            this.page.url = disqus_url;
            this.page.identifier = disqus_identifier;
            this.page.title = disqus_title;
        };
        run_disqus_script('embed.js');
      

    </script>
  









  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("mJL5tPNUUzfehnBQ3njGhTkw-gzGzoHsz", "Eh4WQkFppQhi66Cg9lsyRhyP");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  


</body>
</html>
